public class text {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int l = scanner.nextInt();
        int[] arr = new int[l];
        int[] pre = new int[l - 1];
        for (int i = 0; i < l; i++) {
            arr[i] = scanner.nextInt();
        }
        int res = -1 , cnt = 0;
        for (int i = 0; i < l - 1; i++) {
            boolean ist = true;
            arr[i] = arr[i]^arr[i+1];
            arr[i+1] = arr[i]^arr[i+1];
            arr[i] = arr[i]^arr[i+1];
            for (int j = i > 0 ? i-1 : 0; j < l-1; j++) {
                int sum = arr[j] + arr[j+1];
                if (!cheak(sum)){
                    ist = false;
                    break;
                }
            }
            if (ist){
                cnt++;
                res = i+1;
            }
            arr[i] = arr[i]^arr[i+1];
            arr[i+1] = arr[i]^arr[i+1];
            arr[i] = arr[i]^arr[i+1];
        }
        if (cnt != 1){
            System.out.println(-1);
        }else {
            System.out.println(res);
        }

    }
    static boolean cheak(int a) {
        for (int i = 2; i * i <= a; i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }
}
